from google.appengine.ext import db

from gaeo.controller import BaseController

from model.dictionary import Dictionary

class DictionaryController(BaseController):
    def create(self):
        r = Dictionary(
            message = self.params.get('message', None),
        )
        r.put()
        self.redirect('/dictionary')

    def destroy(self):
        r = Dictionary.get(self.params.get('key'))
        if r is not None:
            r.delete()
        self.redirect('/dictionary')

    def edit(self):
        rec = Dictionary.get(self.params.get('key'))
        if rec:
            setattr(self, 'message', rec.message)
        else:
            setattr(self, 'message', 'Error')

    def index(self):
        query = Dictionary.all()
        self.result = query

    def new(self):
        pass

    def show(self):
        rec = Dictionary.get(self.params.get('key'))
        if rec:
            setattr(self, 'message', rec.message)
        else:
            setattr(self, 'message', 'Error')

    def update(self):
        r = Dictionary.get(self.params.get('key'))
        r.message = self.params.get('message', None)
        r.put()
        self.redirect('/dictionary')
